﻿using System;
using System.Configuration;

using BizElements.BusinessLayer;

namespace BizElements.Web
{
    /// <summary>Creates <see cref="ISearchViewTextSource"/> object configured in application's configuration file.</summary>
    internal static class SearchViewTextSourceFactory
    {
        #region Configuration.

        static readonly string TextSourceAssembly = ConfigurationManager.AppSettings["BizElements.Web.SearchView.TextSourceAssembly"];
        static readonly string TextSourceClass = ConfigurationManager.AppSettings["BizElements.Web.SearchView.TextSourceClass"];

        #endregion

        #region GetTextSource.

        /// <summary>Creates <see cref="ISearchViewTextSource"/> object configured in application's configuration file.</summary>
        public static ISearchViewTextSource GetTextSource()
        {
            ISearchViewTextSource textSource = null;
            if (!string.IsNullOrEmpty(TextSourceAssembly) && !string.IsNullOrEmpty(TextSourceClass))
                textSource = ReflectionUtil.TryCreateInstance(TextSourceAssembly, TextSourceClass) as ISearchViewTextSource;

            if (textSource == null)
                textSource = new SearchViewTextSource();

            // Previously NullSearchViewTextSource wass used as default.
            //if (textSource == null) textSource = NullSearchViewTextSource.GetInstance();

            return textSource;
        }

        #endregion
    }
}